$(function(){
    var form  = $('#frm-contact');
    $('#coda-slider-1').codaSlider({
        crossLinking: true,
        dynamicTabsPosition: '.bn-ct-r-center-menu'
    });
    
    form.xvalidator({
        tooltip: true,
        scrollingAuto: false,
        fields: {
            'txtnom2': {
                disabled: true,
                rule: {
                    required: true
                },
                message: 'Merci d\'entrer votre Nom.'
            },
            'txtprenom': {
                disabled: true,
                rule: {
                    required: true
                },
                message: 'Merci d\'entrer votre Prénom.'
            },
            'txtemail2': {
                disabled: true,
                rule: {
                    required: true, 
                    email: true
                },
                message: 'Merci d\'entrer votre adresse e-mail.'
            },
            'txtmsg': {
                disabled: true,
                rule: {
                    required: true
                },
                message: 'Merci d\'entrer votre message.'
            }
        },
        onSuccess: function(){
            var _ge = getValRadioButtons();
            
            if (_ge) {
                $(this).disabled();
                senddata( $("#hdn-section").val(),$("#hdn-section_name").val(), $("#txtvalido").val(),_ge,$("#txtnom2").val(),$("#txtprenom").val(),$("#txtcodepostal").val(),$("#txtville").val(),$("#txtemail2").val(), $("#txtmsg").val() );
            } else {
                $('#msg-error').show().text('Merci de sélectionner votre status.');
                form.xvalidator('resetform');
            }
        },
        onSubmit: function(e) {
            e.preventDefault();
        }
    });
    
    $('input[type=radio]', form).click(function(){
        form.xvalidator('disabledField', 'txtnom2', false);
        form.xvalidator('disabledField', 'txtprenom', false);
        form.xvalidator('disabledField', 'txtemail2', false);
        form.xvalidator('disabledField', 'txtmsg', false);
        $('#msg-error').text('');
    });

function getValRadioButtons(){
        var _f = "";
        $("input", form).each(function(i){
            $("#frm-contact input:checked").each(function(i){
                if($(this).attr("type")=="radio") 
                    _f = $(this).val();
            }); 	
        }); 
		
        return _f;
    }
	
    function senddata(_section,_section_name,_txtvalido,_genero,_txtnom,_txtprenom,_txtcodepostal,_txtville,_txtemail,_txtmessage){
        $.post("./", {
            _section:_section, 
            _section_name:_section_name,
            _txtvalido:_txtvalido,
            _genero:_genero,
            _txtnom:_txtnom,
            _txtprenom:_txtprenom,
            _txtcodepostal:_txtcodepostal,
            _txtville:_txtville,
            _txtemail:_txtemail,
            _txtmessage:_txtmessage, 
            cache:new Date().getTime()
        }, function(data){
            if($.trim(data)!=""){
                form.reset();
                alert("Votre message a \u00E9t\u00E9 envoy\u00E9 avec succ\u00E8s.");
                document.location = './';
            }
        });
    }
});